﻿using System;
using ZX.Web.UI.Controls;
using ZX.BLL.Extend;
using ZX.SYS.Library;
using ZX.SYS.Bussiness.Message;
using ZX.WebApp.Extend.AjaxData;

namespace ZX.WebApp.EditWidows.SysManager
{
    public partial class ShowAnnounce : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (this.GetStringFromQueryString("Type", "") != null && this.GetStringFromQueryString("Type", "") == "Mes")
                {
                    ShowMesg();
                }
                else
                {
                    Show();
                }
            }
        }

        //展示消息汇总
        private void ShowMesg()
        {
            string id = this.GetStringFromQueryString("ID", "");

            BaseBussnies bll = new BaseBussnies();
            V_Message ann = new V_Message();
            bll.entity = ann;
            ann = (V_Message)bll.GetEntityById(id);
            if (ann != null && !string.IsNullOrEmpty(ann.Title))
            {
                Lb_Title.Text = ann.Title;
                Lb_Time.Text = ann.SendTime.ToLongDateString() + " " + ann.SendTime.ToLongTimeString();
                Lb_Content.Text = Staple.Decode(ann.MsgContent);
                //System.Text.StringBuilder sb=new System.Text.StringBuilder();
                //sb.Append("<a title='"+acce.Name+"'  target='blank' href='../EditWidows/DownLoad.aspx?filename="+acce.Name+"'>");
                //sb.Append(acce.Name);
                //sb.Append("</a>");
                //lblAttach.Text = DownloadFile(ann.ID);

                //标识消息为已读
                BDatMessagePool msgMrg = new BDatMessagePool();
                msgMrg.setSendState(new Guid(id));
            }
        }

        private void Show()
        {
            string id = this.GetStringFromQueryString("ID", "");

            BaseBussnies bll = new BaseBussnies();
            Announce ann = new Announce();
            bll.entity = ann;
            ann = (Announce)bll.GetEntityById(id);
            if (ann != null && !string.IsNullOrEmpty(ann.Subject))
            {
                Lb_Title.Text = ann.Subject;
                Lb_Time.Text = ann.AddTime.ToLongDateString() + " " + ann.AddTime.ToLongTimeString();
                Lb_Content.Text = Staple.Decode(ann.Content);
                //System.Text.StringBuilder sb=new System.Text.StringBuilder();
                //sb.Append("<a title='"+acce.Name+"'  target='blank' href='../EditWidows/DownLoad.aspx?filename="+acce.Name+"'>");
                //sb.Append(acce.Name);
                //sb.Append("</a>");
                lblAttach.Text = DownloadFile(ann.ID);
            }

        }

        private string DownloadFile(Guid announceID)
        {
            BaseBussnies bll = new BaseBussnies();
            string sql = "select * from AnnounceAccessories where AnnounceID='" + announceID + "'";
            AnnounceAccessories announceA = new AnnounceAccessories();
            bll.entity = announceA;
            announceA = (AnnounceAccessories)bll.GetEntityBySqlComm(sql);
            string url = "";
            if (announceA != null)
            {
                Accessories acce = new Accessories();
                bll.entity = acce;
                acce = (Accessories)bll.GetEntityById(announceA.AttachID.ToString());
                //string fileName=HttpUtility.UrlEncode(attach.Name,System.Text.Encoding.UTF8);
                // string webconfigPath = Server.MapPath("../../upload");
                //string strfullpath = webconfigPath + "\\" + acce.Name;
                string displayName = acce.Name.Length > 20 ? acce.Name.Substring(0, 20) : acce.Name;
                url = "<a href='../.." + acce.Path + "'>" + displayName + "</a>";

            }
            else
            {
                url = "无附件";
            }
            return url;
        }
    }
}